/*
 * Project Name: cms_web
 * File Name: DownPageTag.java
 * Copyright: ZKTeco Corporation 2015
 * Description: TODO 请在此处添加对本文件的描述
 * Creator: Administrator
 * Create Date: 2015年3月23日 下午3:13:10
 */
package com.shishuo.cms.tag;

import static freemarker.template.ObjectWrapper.BEANS_WRAPPER;

import java.io.IOException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.entity.DownPageEntity;
import com.shishuo.cms.entity.PictureEntity;
import com.shishuo.cms.plugin.TagPlugin;
import com.shishuo.cms.service.DownPageService;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

@Service
public class DownPageTag extends BaseTagPlugin
{

	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException
	{
		long id = Long.parseLong(params.get("id").toString());
		int page = Integer.parseInt(params.get("p").toString());
		try {
			DownPageEntity downPageEntity = downPageService.getById(id);
			if (null != downPageEntity) {
				env.setVariable("tag_down", BEANS_WRAPPER.wrap(downPageEntity));
			}
			body.render(env.getOut());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
